{template 'common/header'}
<div class="main">
	<ul class="nav nav-tabs">
		<li {if $_GPC['do'] == 'manage' || $_GPC['do'] == '' } class="active"{/if}>
			<a href="{php echo $this->createWebUrl('manage');}">管理中心</a>
		</li>
		<li {if $_GPC['do'] == 'post'} class="active"{/if}>
			<a href="{php echo url('platform/reply/post',array('m'=>'dg_dati'));}">添加答题活动</a>
		</li>
	</ul>
	<div class="panel panel-default">
		<div class="panel-body table-responsive">
			<table class="table table-hover">
				<thead class="navbar-inner">
					<tr>
						<th class='with-checkbox' style="width: 50px;"></th>
						<th style="width: 150px;">活动名称</th>
						<th style="width: 180px;">开始时间/结束时间</th>
						<th style="width: 100px;">活动状态</th>
						<th style="width: 300px;">操作</th>
					</tr>
				</thead>
				<tbody>
					{loop $list $row}
					<tr>
						<td class="with-checkbox"><input type="checkbox" name="check"
							value="{$row['rid']}"></td>
						<td>{$row['huodongname']}</td>
						<td>{php echo date("Y/m/d h:i",$row['start_time'])}<br> {php echo date("Y/m/d  h:i",$row['end_time'])}
						</td>
						<?php 
						$nowtime = time();
						$status_str="";
						if ($row['start_time'] > $nowtime) {
							$status_str= '<span class="label label-warning">未开始</span>';
						} else if ($row['end_time'] < $nowtime) {
							$status_str= '<span class="label label-default ">已结束</span>';
						} else {
							if ($row['status'] == 1) {
								$status_str= '<span class="label label-success">已开始</span>';
							} else {
								$status_str= '<span class="label label-default ">已暂停</span>';
							}
						}
						?>
						<td>{$status_str}</td>
						<td>
						  	<a class="btn btn-default" data-toggle="tooltip" data-placement="top"
							href="{php echo $this->createWebUrl('hexiaomanage',array('rid'=>$row['rid']))}"
							onclick="" title="核销管理">核销记录</a> 
						
							<a class="btn btn-default" data-toggle="tooltip"
							data-placement="top"
							href="{php echo url('platform/reply/post',array('m'=>'dg_dati','rid'=>$row['rid']));}"
							title="编辑"><i class="fa fa-edit"></i></a> 
							
							<a class="btn btn-default" data-toggle="tooltip" data-placement="top"
							href="{php echo $this->createWebUrl('datimanage',array('rid'=>$row['rid']))}"
							onclick="" title="答题管理"><i class="fa fa-cog"></i></a> 
							
							{if $row['status']==2 } 
							<a class="btn btn-default" title="开始活动"
							data-placement="top" href="#"
							onclick="drop_confirm('您确定要开始吗,设置中途可以随时修改!', '{php echo $this->createWebUrl('hdcontrol',array('rid'=>$row['rid'],'status'=>1))}');"><i
							class="fa fa-play"></i></a> 
							{/if} 
							
							{if $row['status']==1} 
							<a class="btn btn-default" title="结束活动" data-placement="top" href="#"
							onclick="drop_confirm('您确定要暂停吗,设置中途可以随时修改!', '{php echo $this->createWebUrl('hdcontrol',array('rid'=>$row['rid'],'status'=>2))}');"><i
							class="fa fa-stop"></i></a> {/if} 
							<a class="btn btn-default" data-toggle="tooltip" data-placement="top" href="{php echo $this->createWebUrl('record',array('rid'=>$row['rid']))}" onclick="" title="参与记录"><i class="fa fa-bar-chart"></i></a>
							<a class="btn btn-default"
							data-toggle="tooltip" data-placement="top" href="#"
							onclick="drop_confirm('您确定要删除吗?', '{php echo $this->createWebUrl('delete',array('rid'=>$row['rid']))}');"
							title="删除"><i class="fa fa-times"></i></a>
						</td>
					</tr>
					{/loop}
					<tr>
						<td><input type="checkbox" class="check_all" value="0" /></td>
						<td colspan="5"><input type="button" class="btn btn-primary"
							name="deleteall" value="删除选择的" /></td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
	{$pager}
</div>
<script>
require(['bootstrap'],function($){
	$('.btn').tooltip();
});
$(function(){
    $(".check_all").click(function(){
       var checked = $(this).get(0).checked;
		$(':checkbox').each(function(){this.checked = checked});
    });
	$("input[name=deleteall]").click(function(){
		var check = $("input:checked");
		if(check.length<1){
			alert('请选择要删除的记录!');
			return false;
		}
        if( confirm("确认要删除选择的记录?")){
			var rid = new Array();
			check.each(function(i){
				if($(this).val()!=0){
					rid[i] = $(this).val();
				}
			});
			//debugger;
			$.post("{php echo $this->createWebUrl('deleteall')}", {ridArr:rid},function(data){
				if (data.errno ==0)
				{
					location.reload();
				} else {
					alert(data.error);
				}
	
	
			},'json');
		}
	});
});
</script>
<script>
function drop_confirm(msg, url){
    if(confirm(msg)){
        window.location = url;
    }
}
</script>
{template 'common/footer'}
